#!/bin/zsh

# set default cheat directory
cheatpath=${DOTFILES}/config/cheat/cheatsheets/personal

fcmd() {
    cd "$cheatpath"

    # start fuzzy searching
    fzfsearch="$(grep '^#' * | fzf)"

    # store results as variables
    cheatbasename="$(printf "$fzfsearch" | cut -d ':' -f1)"
    cheatcodetitle="$(printf "$fzfsearch" | cut -d ':' -f2-)"

    # copy paragraph of code we selected to Linux X clipboard
    #[ -x "$(command -v xclip)" ] && cheat "$cheatbasename" | sed -n "/$cheatcodetitle/,/^$/p" | sed '/^$/d' | sed '1d' | xclip -selection clipboard

    # copy paragraph of code we selected to TMUX clipboard
    # pidof tmux >/dev/null && tmux set-buffer "$(cheat "$cheatbasename" | sed -n "/$cheatcodetitle/,/^$/p" | sed '/^$/d' | sed '1d')"

    # copy paragraph of code we selected to OSX clipboard
    [ -x "$(command -v pbcopy)" ] && cheat "$cheatbasename" | sed -n "/$cheatcodetitle/,/^$/p" | sed '/^$/d' | sed '1d' | pbcopy

}



